//
//  THTaskReportVC.m
//  YJB
//
//  Created by YJB on 2016/11/28.
//  Copyright © 2016年 YJB. All rights reserved.
//

#import "THTaskReportVC.h"
#import "YJTextView.h"
#import "YJGlobalHeader.h"
#import "YJUserDefaultTool.h"
#import "YJNetworkTool.h"

@interface THTaskReportVC ()<UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UILabel *topic;
@property (weak, nonatomic) IBOutlet UILabel *reporter;
@property (weak, nonatomic) IBOutlet YJTextView *reason;
@property (weak, nonatomic) IBOutlet UITextField *QQNum;
@property (weak, nonatomic) IBOutlet UIImageView *bgImageView;

@end

@implementation THTaskReportVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"在线举报";
    _reason.placeholder = @"请填写举报原因，请不要恶意举报，一经查实将会影响个人信誉分";
    _reason.placeholderColor = kUIColorFromRGB(0x666666);
    _reason.layer.borderWidth = 0.5;
    _reason.layer.borderColor = kUIColorFromRGB(0x999999).CGColor;
    _QQNum.layer.borderWidth = 0.5;
    _QQNum.layer.borderColor = kUIColorFromRGB(0x999999).CGColor;
    _reporter.text = [YJUserDefaultTool readUserName];
    _topic.text = [NSString stringWithFormat:@"举报该任务:%@",_taskTitle];
    
    YJWeakSelf
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]init];
    [tap.rac_gestureSignal subscribeNext:^(id x) {
        [weakSelf.view endEditing:YES];
    }];
    _bgImageView.userInteractionEnabled = YES;
    [_bgImageView addGestureRecognizer:tap];

}

-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    [self.view endEditing:YES];
}
- (IBAction)publishBtnClick:(UIButton *)sender
{
    [self.view endEditing:YES];
    if (_reason.text.length == 0)
    {
        [MBProgressHUD showError:@"请填写举报原因" toView:self.view];
        return;
    }
    if (!_QQNum.text.length)
    {
        _QQNum.text = @"";
    }

    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    NSString *userName = [YJUserDefaultTool readUserName];
    NSString *md5Key = [YJUserDefaultTool readKeyID];
    params[@"action"] = @"set_report_add";
    params[@"makegold"] = @{@"username":userName,
                            @"report_id":_ID,
                            @"report_title":_taskTitle,
                            @"type":_taskType,
                            @"content":_reason.text,
                            @"qqnum":_QQNum.text,
                            @"user_info":userName,
                            @"phone_info":@"iOS",
                            @"md5_key":md5Key};
    [MBProgressHUD showMessage:@"" toView:self.view];
    [YJNetworkTool postWithUrl:THURL(@"report.php") parameters:params success:^(id responseObject) {
        NSString *code = responseObject[@"return"][@"code"];
        [MBProgressHUD hideHUDForView:self.view];
        if (code.integerValue == 200)
        {
            [MBProgressHUD showSuccess:@"已提交，请耐心等待审核结果"];
            [self.navigationController popViewControllerAnimated:YES];
        }
        else
        {
            NSString *message = responseObject[@"return"][@"message"];
            [MBProgressHUD showError:message toView:self.view];
        }
    } failure:^(NSError *error) {
        [MBProgressHUD hideHUDForView:self.view];
        [MBProgressHUD showError:@"网络不佳，稍后重试" toView:self.view];
    }];
}

- (IBAction)cancelBtnClick:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

@end
